# -*- coding: utf-8 -*-
"""
    Time    : 2020/12/26 5:35 下午
    Author  : Thinkgamer
    File    : add02-找出特定子串在字符串中出现的所有位置.py
    Desc    : eg: 对于给定的字符串 abc, 在字符串 ababcdeabc 中出现的位置为[2,3,4], [7,8,9]
"""


def find_all_location(arr, t):
	i, j = 0, 0
	# 记录最终的结果
	result = list()
	# 记录单次的结果
	temp = list()
	while i < len(arr) and j < len(t):
		if arr[i] == t[j]:
			temp.append(i)
			# 判断当前的匹配位数是否已经满足
			if len(temp) == len(t):
				result.append(temp)
				i += 1
				j = 0
				temp = list()
			else:
				i += 1
				j += 1
		else:
			i = i if arr[i] == t[0] else i + 1
			j = 0
			temp = list()

	return result


arr = "ababcdeabc"
t = "abc"
result = find_all_location(arr, t)
print(result)
